package com.atguigu.flink.chapter05.Transform;

import org.apache.flink.streaming.api.datastream.ConnectedStreams;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.co.CoMapFunction;

/**
 * TODO
 *
 * @author cjp
 * @version 1.0
 * @date 2021/1/20 14:06
 */
public class Flink07_Connect {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);

        DataStreamSource<Integer> numDS = env.fromElements(1, 2, 3, 4, 5, 6);
        DataStreamSource<String> strDS = env.fromElements("a", "b", "c", "d");


        //TODO connect
        ConnectedStreams<Integer, String> connect = numDS.connect(strDS);

        SingleOutputStreamOperator<Object> resultDS = connect.map(new CoMapFunction<Integer, String, Object>() {
            @Override
            public Object map1(Integer value) throws Exception {
                return "我是map1：" + value;
            }

            @Override
            public Object map2(String value) throws Exception {
                return "我是map2：" + value;
            }
        });

        resultDS.print();


        env.execute();
    }

}
/*
    connect:
        1、只能连接 两条 流
        2、两条流的数据类型可以不一样
 */